import {Notification, Message, Modal} from '@arco-design/web-vue';

export class MsgUtil {

    static confirm(content: string, onConfirm: any, title = '操作确认', okText = '确认') {
        Modal.warning({
            title,
            okText,
            draggable: false,
            width: 400,
            titleAlign:'start' ,
            alignCenter:false,
            hideCancel: false,
            escToClose: true,
            renderToBody:true,
            top: 60,
            maskClosable: false,

            content: () => content,
            onOk: () => onConfirm(),

        });
    }

    static notify(title, content, theme:'success' |'info' |'error' = 'success') {
        Notification[theme]({
            title, content,
        })
    }

    static message(content: string, theme = 'error') {
        Message[theme]({content})
    }

    static alert(title, content, theme   :'success' |'info' |'error' = 'success', callback: any = null) {
        Modal[theme]({
                title,
                content,
                onOk:()=>{
                    if (callback !== null && typeof callback === "function") callback();
                }
            }
        );
    }

    /**
     * 下载导出结果
     * */
    static downLoad(data) {
        const modal = Modal.success({
            title: '数据导出成功',
            content: `数据导出成功 , 本次导出 ${data.count}条数据`,
            okText: '点击下载导出结果',
            escToClose: false,
            closable: false,
            onOk: () => {
                window.open(data.downUrl, '_blank')
                modal.close()
            },
        })
    }

}
